#include "qscriptobjectlistwidgetbar.h"
#include "ui_qscriptobjectlistwidgetbar.h"

#include <QPainter>
#include <QStyleOption>

QScriptObjectListWidgetBar::QScriptObjectListWidgetBar(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::QScriptObjectListWidgetBar)
{
    ui->setupUi(this);
    setProperty("panelwidget", true);
    setProperty("panelwidget_singlerow", true);
    setProperty("lightColored", false);
    setFixedHeight(25);
    m_findEdit=new FancyLineEdit(this);
    m_findEdit->setButtonVisible(FancyLineEdit::Right,true);
    ui->horizontalLayout->insertWidget(1,m_findEdit,1);

    connect(m_findEdit,SIGNAL(rightButtonClicked()),m_findEdit,SLOT(clear()));
    connect(ui->findNextButton,SIGNAL(clicked()),this,SLOT(findNext_slot()));
    connect(ui->findPreviousButton,SIGNAL(clicked()),this,SLOT(findPrev_slot()));
}

QScriptObjectListWidgetBar::~QScriptObjectListWidgetBar()
{
    delete ui;
}

void QScriptObjectListWidgetBar::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)
    QPainter painter(this);
    QStyleOption option;
    option.rect = rect();
    option.state = QStyle::State_Horizontal;
    style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this);
}

void QScriptObjectListWidgetBar::findNext_slot()
{
    QString str=m_findEdit->text();
    if(str!="")
    {
        emit findNext(str);
    }
}

void QScriptObjectListWidgetBar::findPrev_slot()
{
    QString str=m_findEdit->text();
    if(str!="")
    {
        emit findPrev(str);
    }
}
